<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class photoController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('photo.form');
    }

    public function list()
    {
        $images = DB::table('photo') -> paginate(4);
        return view('photo.list',['img'=>$images]);
    }

    public function doLoad(Request $request)
    {

        if ($request -> hasFile('img')) {
            $filename = time().rand(1111,9999);
            $suffix = $request -> file('img') -> getClientOriginalExtension();
            $dirname = './uploads/';
            $file = $filename.'.'.$suffix;
            $request -> file('img') -> move($dirname,$file);
            $img = trim($dirname.$file,'.');
            DB::table('photo') -> insert(
                ['img'=>$img]
            );
        }
        $images = DB::table('photo') -> paginate(4);
        echo json_encode($images);
        //return view('photo.info',['img'=>$images]);
    }

}
